package cn.ctvonline.android.kaopu.base;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * Created by dujian on 15/11/12.
 */
public class IncomingHandler<T extends Activity> extends Handler {
    private MessageHandleListener onMessageHandleListener;
    private WeakReference<T> mWeakRef;

    public IncomingHandler(T t) {
        mWeakRef = new WeakReference<T>(t);
    }

    @Override
    public void handleMessage(Message msg) {
        T t = mWeakRef.get();
        if (t == null) {
            return;
        }
        if (onMessageHandleListener != null) {
            onMessageHandleListener.onHandlerMessage(msg);
        }
    }

    public MessageHandleListener getOnMessageHandleListener() {
        return onMessageHandleListener;
    }

    public void setOnMessageHandleListener(MessageHandleListener onMessageHandleListener) {
        this.onMessageHandleListener = onMessageHandleListener;
    }
}
